
var app = new Vue({
	el: '#main-container',
	data: {
		loadingPage: true,
		tableData: {
			total: 0,
			list: [{filterStationFlag: "NO", filterTimeFlag: "NO"}],
		},
	},
	created: function () {
	},
	mounted: function () {
	},
	methods: {
		/**
		 * 获取新的数据
		 */
		getNewData: function (opt) {
			var _this = this;
			let guid = '';
			if (opt == 1) {
				guid = $("#guid").val();
			}
			if (opt == 2) {
				guid = $("#serverId").val();
			}
			$.ajax({
				url: postPath + '/accesscontrol/filterfield/getDataList',
				type: "POST",
				data: guid,
				isShowLoader: true,
				dataType: 'json',
				contentType: 'application/json;charset=UTF-8',
				success: function (res) {
					if (res && res.success) {
						_this.tableData.list = res.data;
					}
				}
			});
		},
		save: function () {
			var _this = this;
			var arr = [];
			for (var i = 0; i < _this.tableData.list.length; i++) {
				var item = _this.tableData.list[i];
				//过滤类型(STCD 测站，TM时间)
				if (item.filterStationFlag == 'YES') {
					arr.push({
						serviceId: item.serviceId,
						filterType: 'STCD',
						fieldId: item.fieldId,
						fieldCode: item.fieldname,
						fieldType: item.fieldtype,
					});
				}
				if (item.filterTimeFlag == 'YES') {
					arr.push({
						serviceId: item.serviceId,
						filterType: 'TM',
						fieldId: item.fieldId,
						fieldCode: item.fieldname,
						fieldType: item.fieldtype,
					});
				}
			}

			$.ajax({
				type: 'POST',
				url: postPath + '/accesscontrol/filterfield/save',
				data: JSON.stringify({
					serviceId: item.serviceId,
					acServiceFilterFieldList: arr
				}),
				dataType: 'json',
				contentType: 'application/json;charset=UTF-8',
				success: function (res) {
					if (res.success == true) {
						showMsg("操作成功!", "success");
					} else {
						showMsg("操作失败,请稍后重试!", "error");
					}
				}
			});

		},
	}

})
